package com.xiaobaibai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaobaibai.dao.AnnouncementDao;
import com.xiaobaibai.entity.Announcement;
import com.xiaobaibai.service.IAnnouncementService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaobaibai
 * @since 2020-10-20
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementDao, Announcement> implements IAnnouncementService {

    @Cacheable(value = "announcement",key = "#root.methodName")
    @Override
    public List<Announcement> getAnnouncementTitleList() {
        QueryWrapper<Announcement> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("title");
        List<Announcement> list = this.list(queryWrapper);
        return list;
    }

    @Cacheable(value = "announcement",key = "#root.methodName")
    @Override
    public List<Announcement> getAnnouncementListNoContent() {
        QueryWrapper<Announcement> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("id","title","create_time");
        List<Announcement> list = this.list(queryWrapper);
        return list;
    }

    @Cacheable(value = "announcement",key = "#root.methodName+'-'+#id")
    @Override
    public Announcement getAnnouncementItem(Integer id) {
        QueryWrapper<Announcement> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",id);
        queryWrapper.select("title","content","create_time");
        return this.getOne(queryWrapper);
    }

}
